function diff = T_lam_matrix_HJB_t( ln_m_h, ln_m, q, param, aux) 

    % calculates the matrix given m_h and lambda

    [delta]=del_num(ln_m_h,ln_m,q,param);
    delta_p=[delta(2:end)-delta(1:end-1)]./[ln_m(2:end)-ln_m(1:end-1)];
    delta_p=[delta_p(1);delta_p(1:end-1)/2+delta_p(2:end)/2;delta_p(end)];

    delta=delta+param.zeta;

    T_lam=sparse(aux.n_m,aux.n_m);
    T_lam2=sparse(aux.n_m,aux.n_m);

    ind_down = 1+1 + (aux.n_m+1).*[0:aux.n_m-2];
    ind_up   = 1-1 + (aux.n_m+1).*[1:aux.n_m-1];
    ind_stay = 1   + (aux.n_m+1).*[0:aux.n_m-1];

    dinv=(1-param.alpha)./(ln_m(2:end)-ln_m(1:end-1));

    down_lam =   ones(aux.n_m-1,1).*(1./2.*dinv.*delta(2:end));
    up_lam   = - ones(aux.n_m-1,1).*(1./2.*dinv.*delta(1:end-1));
    stay_lam   = ones(aux.n_m,1).*(+1./2.*([dinv;dinv(end)]-[dinv(1);dinv])).*delta;      

    stay_lam2   = ones(aux.n_m,1).*(delta-(1-param.alpha).*delta_p);      

    T_lam(ind_down) = down_lam;
    T_lam(ind_up) = up_lam;
    T_lam(ind_stay) = stay_lam;

    T_lam(1,1) = 0+ dinv(1).*delta(1);
    T_lam(1,2) = -dinv(1).*delta(1);

    T_lam(aux.n_m,aux.n_m) = 0 - dinv(end).*delta(end);
    T_lam(aux.n_m,aux.n_m-1) = dinv(end).*delta(end);

    T_lam2(ind_stay) = stay_lam2;

    diff.T_lam=T_lam;
    diff.T_lam2=T_lam2;

end